home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 1 / ETO Development Tools 1.iso / Essentials / MacApp Documentation / MacApp AppleLink Messages / MacApp.Tech$ Jun 89 / V0003-Comparing Objects |-Jun89 < prev    next >
Encoding:
Text File  |  1989-06-26  |  2.8 KB  |  75 lines  |  [TEXT/GEOL]

  1. Item    4950158                         3-June-89        09:37
  2.  
  3. From:   CDA0373                         AUC Lakehead U, Alan Day
  4.  
  5. To:     MACAPP.TEST                     MacApp SQA Team
  6.  
  7. cc:     MACAPP.TECH$                    MACAPP Tech
  8.  
  9. Sub:    Comparing Objects |CDA0373
  10.  
  11. Dear MacApp Team,
  12.  
  13. I'd like to make a plea for a new general method for TObject, namely Compare.
  14. The default action would be something like the following:
  15.  
  16.     FUNCTION TObject.Compare(anObject:TObject):INTEGER;
  17.         VAR p,q:LONGINT;
  18.     BEGIN
  19.     p:= LONGINT(SELF);
  20.     q:= LONGINT(anObject);
  21.     IF p < q THEN
  22.         Compare:= kALessThanB
  23.     ELSE IF p > q   THEN
  24.         Compare:= kAGreaterThanB
  25.     ELSE { p = q }
  26.         Compare:= kAEqualB;
  27.     END;
  28.  
  29. Such an implementation would require a minimal adjustment by making the UList.p
  30. constants global and defaulting TSortedList.Compare(item1,item2) to
  31. item1.Compare(item2).
  32.  
  33. It would also allow easy compare methods for specialized objects. For example,
  34. if someone had Finder-styled named objects, i.e. objects with a string field,
  35. say TStrObject, one could override this Compare to produce
  36.  
  37.      FUNCTION TStrObject.Compare(anObject:TObject):INTEGER;OVERRIDE;
  38.         VAR p,q:Str255;
  39.     BEGIN
  40.     p:= TStrObject(SELF).fString;
  41.     q:= TStrObject(anObject).fString;
  42.     IF p < q THEN
  43.         Compare:= kALessThanB
  44.     ELSE IF p > q   THEN
  45.         Compare:= kAGreaterThanB
  46.     ELSE { p = q and the user didn't provide unique names }
  47.         Compare:= INHERITED Compare(anObject);
  48.     END;
  49.  
  50. Perhaps the default TSortedList.Compare could even call, in debug mode,
  51. something like GetEltType(item1).Compare(item2) so that such lists always have
  52. a default sorting which, of course, can be still overridden.
  53.  
  54. My rationale for this is that Compare seems to be a property of objects, not
  55. the lists which contain them; and that the above is a canonical content-free
  56. way to compare such, which has the crucial property that aItem.Compare(bItem) =
  57. kAEqualB if and only if aItem = bItem. Overrides can easily produce content
  58. sensitive versions of this: aItem.Compare(bItem) = kAEqualB if and only if
  59. "Content"(aItem) = "Content"(bItem) as in the TStrObject version above.
  60.  
  61. Since I do not have 2.0ß9, I do not know if such a method has been implemented.
  62. Since my in-depth knowledge of programming philosophy and practices is limited,
  63. I cannot estimate all the ramifications of such a new method. I would like to
  64. suggest this method though, and if the idea is dumb find out why. [because I am
  65. seriously considering tweaking my MacApp to include this method]
  66.  
  67. If this idea is reasonable, the minimal code and documentation changes required
  68. might make it a reasonable last minute inclusion for 2.0ß9. If deadlines are
  69. long past [and the idea holds water], could it be considered for the next
  70. release?
  71.  
  72.     Alan    CDA0373
  73.  
  74.  
  75.